import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.Animation
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator

fun main(args: Array<String>)
{
    LwjglApplication(MainPage(), config {
        width = 480
        height = 320
        useGL20 = true
        backgroundFPS = 30
        foregroundFPS = 120
        initialBackgroundColor = Color.GRAY
        resizable = false
        title = "TTFDemo"
    })
}

class MainPage : ApplicationAdapter()
{
    lateinit var generator: FreeTypeFontGenerator
    lateinit var fontData: FreeTypeFontGenerator.FreeTypeBitmapFontData
    lateinit var batch: SpriteBatch
    lateinit var bitmapFont: BitmapFont

    override fun create()
    {
        generator = FreeTypeFontGenerator(Gdx.files.internal("hksn.ttf"))
        fontData = generator.generateDataUnRepeat(25, "你认我做大哥，我教你梳中分123--蕾哥哥", false)
        batch = SpriteBatch()
        bitmapFont = BitmapFont(fontData, fontData.textureRegions, false)
        bitmapFont.color = Color.RED
    }

    override fun render()
    {
        clear()
        batch.begin()

        bitmapFont.draw(batch, "你认我做大哥，我教你梳中分", 20f, Gdx.graphics.floatHeight / 2)
        bitmapFont.draw(batch, "--蕾哥哥", Gdx.graphics.floatWidth - 100, Gdx.graphics.floatHeight / 2 - 50)

        batch.end()
    }
}